#include "Direct3DFramework.h"

int Direct3DFramework::updateCamera(BeanieCamera* a_camera)
{
	m_camera.m_pos.x = (m_window->m_windowWidth/2.0f) - a_camera->m_pos.x;
	m_camera.m_pos.y = (m_window->m_windowHeight/2.0f) - a_camera->m_pos.y;
	return GPX_SUCCESS;
}

int Direct3DFramework::updateTransform(BeanieTexture* a_texture,
	V2DF a_transform, V2DF a_scale, float a_rotate)
{
	//get texture with given id
	D3DFTexture* texture = m_textureList[a_texture->m_texId];

	//empty matrices
	D3DXMatrixIdentity(&texture->m_matrices[a_texture->m_matId].m_scale);
	D3DXMatrixIdentity(&texture->m_matrices[a_texture->m_matId].m_rotate);
	D3DXMatrixIdentity(&texture->m_matrices[a_texture->m_matId].m_translate);
	D3DXMatrixIdentity(&texture->m_matrices[a_texture->m_matId].m_world);

	//create scaling matrix
	D3DXMatrixScaling(&texture->m_matrices[a_texture->m_matId].m_scale,
		a_scale.x,a_scale.y,1.0f);

	//create rotation matrix
	D3DXMatrixRotationZ(&texture->m_matrices[a_texture->m_matId].m_rotate,
		D3DXToRadian(a_rotate));

	//create translation matrix
	D3DXMatrixTranslation(&texture->m_matrices[a_texture->m_matId].m_translate,
		a_transform.x,a_transform.y,0.0f);

	D3DXMATRIX cam;
	D3DXMatrixIdentity(&cam);
	D3DXMatrixTranslation(&cam,m_camera.m_pos.x,m_camera.m_pos.y,0.0f);
	
	//create world matrix
	texture->m_matrices[a_texture->m_matId].m_world = 
		(texture->m_matrices[a_texture->m_matId].m_scale
		*texture->m_matrices[a_texture->m_matId].m_rotate * cam
		*texture->m_matrices[a_texture->m_matId].m_translate);

	return GPX_SUCCESS;
}